import { defineStore } from 'pinia'
import axios from '../utils/axios'

export const useBorrowStore = defineStore('borrow', () => {
  const borrowResource = async (borrowData: any) => {
    try {
      await axios.post('/user/borrow/lend', borrowData)
      return true
    } catch (error) {
      console.error('借用资源失败:', error)
      return false
    }
  }

  const returnResource = async (resourceId: number) => {
    try {
      await axios.get(`/user/borrow/return/${resourceId}`)
      return true
    } catch (error) {
      console.error('归还资源失败:', error)
      return false
    }
  }

  const submitPenalty = async (penaltyAmount: number, recordsId: number) => {
    try {
      await axios.get(`/user/borrow/submit/${penaltyAmount}?RecordsId=${recordsId}`)
      return true
    } catch (error) {
      console.error('缴纳罚款失败:', error)
      return false
    }
  }

  return {
    borrowResource,
    returnResource,
    submitPenalty
  }
}) 